kmpkg_check_linkage(ONLY_STATIC_LIBRARY)

kmpkg_from_gitee(
    OUT_SOURCE_PATH SOURCE_PATH
    REPO kumo-pub/nmslib
    REF v2.1.1
    SHA512 6533d4fa82f7ab1cd3ceb5fcf12b5e4bbdddba961d913bc1683a7021fe14cea396a9dfdede9bb7057d2766b959433f197433b8472fc5ae3798bbab374611b93d
    HEAD_REF master
)

# TODO: check SSE and AVX availability and set corresponding tags
kmpkg_cmake_configure(
    SOURCE_PATH "${SOURCE_PATH}/similarity_search"
)

kmpkg_cmake_install()
kmpkg_copy_pdbs()

# Move headers into separate folder
set(SUBFOLDERS factory method space)
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/include/nmslib")
foreach(SUBFOLDER ${SUBFOLDERS})
    file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/include/nmslib/${SUBFOLDER}")
endforeach()

file(GLOB HEADERS "${CURRENT_PACKAGES_DIR}/include/*.h" "${CURRENT_PACKAGES_DIR}/include/*/*.h")
foreach(HEADER ${HEADERS})
    string(REPLACE "${CURRENT_PACKAGES_DIR}/include" "${CURRENT_PACKAGES_DIR}/include/nmslib" MOVED_HEADER "${HEADER}")
    file(RENAME "${HEADER}" "${MOVED_HEADER}")
endforeach(HEADER ${HEADERS})

foreach(SUBFOLDER ${SUBFOLDERS})
    file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/include/${SUBFOLDER}/")
endforeach()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

# Put the license file where kmpkg expects it
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
